package com.esri.core.internal.catalog;

import com.esri.core.internal.io.handler.h;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class Folder {
    private String a;
    private String b;
    private String c;
    private List<Item> d = new ArrayList();
    private Date e;
    private boolean f;
    private Catalog g;

    /* JADX INFO: Access modifiers changed from: package-private */
    public Folder(Catalog catalog, boolean z) {
        this.g = catalog;
        this.f = z;
    }

    public String getFolderName() {
        return this.a;
    }

    public boolean isRootFolder() {
        return this.f;
    }

    public Date getCreatedDate() {
        if (this.f) {
            throw new RuntimeException("Created date is only available for sub folders");
        }
        return this.e;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void setUsername(String str) {
        this.c = str;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void setFolderName(String str) {
        this.a = str;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void setItems(List<Item> list) {
        this.d = list;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void setId(String str) {
        this.b = str;
    }

    public List<Item> getItems() throws CatalogException {
        HashMap hashMap;
        if (this.f) {
            return this.d;
        }
        List<Item> list = this.d;
        if (list != null && list.size() > 0) {
            return this.d;
        }
        if (this.g.getUserToken() != null) {
            hashMap = new HashMap();
            hashMap.put("token", this.g.getUserToken());
        } else {
            hashMap = null;
        }
        try {
            JsonParser a = h.a(this.g.getUrl() + "/sharing/content/users/" + this.c + "/" + this.b, hashMap, this.g.a());
            while (a.nextToken() != JsonToken.END_OBJECT) {
                String currentName = a.getCurrentName();
                a.nextToken();
                if (currentName.equals("username")) {
                    a.getText();
                } else if (currentName.equals("currentFolder")) {
                    a.skipChildren();
                } else if (!currentName.equals("items")) {
                    continue;
                } else if (a.getCurrentToken() != JsonToken.START_ARRAY) {
                    throw new RuntimeException("Invalid Json response..");
                } else {
                    this.d = new ArrayList();
                    while (a.nextToken() != JsonToken.END_ARRAY) {
                        Item item = new Item(this.g.getUrl());
                        item.fromJson(a, null, this.g);
                        this.d.add(item);
                    }
                }
            }
            return this.d;
        } catch (Exception e) {
            throw new CatalogException("Unable to get the Items stored in this folder", e.getCause());
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void setCreatedDate(Date date) {
        this.e = date;
    }
}
